<?php

namespace Admin\Controller;

class ConfigController extends CommonController
{

    public function _initialize()
    {
        $config                  = D('Config')->get_config();
        $config['YTATA_STATISTICS'] = htmlspecialchars($config['YTATA_STATISTICS'], ENT_QUOTES);
        $this->assign('show', $config);
    }

    // 网站配置
    public function config()
    {
        $this->display();
    }

    // 其它
    public function other()
    {
        $this->display();
    }

    // 电子地图
    public function map()
    {
        $this->display();
    }

    // 积分配置
    public function gold()
    {
        $this->display();
    }

    // 注册设置
    public function reg()
    {
        $this->display();
    }

    public function upload()
    {
        $this->display();
    }

    // 保存配置
    public function edit()
    {
        if (IS_POST) {
            $data   = M('Config');
            $config = I('post.');
            //$intval_array=array('YTATA_GOLD_SEND_MB','YTATA_GOLD_QUANTIFIER_ANONYMOUS','YTATA_MAP_ZOOM');
            foreach ($config as $key => $v) {
                $where['name']  = "{$key}";
                $savev['value'] = "{$v}";
                if ($where['name'] == 'YTATA_SITE_DOMAIN') {
                    $savev['value'] = rtrim($savev['value'], '/');
                }
                if ($where['name'] == 'YTATA_GOLD_SEND_MB') {
                    $savev['value'] = intval($savev['value']) < 0 ? 0 : intval($savev['value']);
                }
                if ($where['name'] == 'YTATA_GOLD_QUANTIFIER_ANONYMOUS') {
                    $savev['value'] = intval($savev['value']) < 0 ? 0 : intval($savev['value']);
                }
                if ($where['name'] == 'YTATA_STATISTICS') {
                    $savev['value'] = htmlspecialchars_decode($savev['value'], ENT_QUOTES);
                }
                if ($where['name'] == 'URL_MODEL') {
                    $savev['value'] = intval($savev['value']) == 1 ? 2 : 0;
                    F('nav', null);//更新导航的链接样式
                }
                if ($where['name'] == 'UPLOAD_TYPE_CONFIG') {
                    $savev['value'] = serialize($v);
                }
                $data->where($where)->save($savev);
            }
            if (!ytata_refresh_cache('config')) {
                $this->error('生成缓存失败！');
            }
            $this->success('保存完成');
        } else {
            $this->error('参数错误');
        }
    }
}